Skip to content

feat: add request config#34

Closed
liulinboyi wants to merge 1 commit into
microsoft:mainfrom
liulinboyi:feat/addConfig
Closed

feat: add request config#34
liulinboyi wants to merge 1 commit into
microsoft:mainfrom
liulinboyi:feat/addConfig

Conversation

@liulinboyi
Copy link
Copy Markdown

@liulinboyi liulinboyi commented Jul 21, 2023

Add request config
eg: For Proxy request:

examples\calendar\src\main.ts

import fs from "fs";
import path from "path";
import dotenv from "dotenv";
import { createLanguageModel, createJsonTranslator, processRequests } from "typechat";
import { CalendarActions } from './calendarActionsSchema';
import { SocksProxyAgent } from 'socks-proxy-agent' // 7.0.0

// TODO: use local .env file.
dotenv.config({ path: path.join(__dirname, "../../../.env") });

const PROXY_HOST = "127.0.0.1";
const PROXY_PORT = "1080";
const model = createLanguageModel(process.env, 
    {
        httpsAgent: new SocksProxyAgent({
            hostname: PROXY_HOST,
            // userId: 'xxx@gmail.com',
            // password: 'xxxxx'
            host: PROXY_HOST,
            port: PROXY_PORT,
            rejectUnauthorized: false,
        } as any)
    }
);
const schema = fs.readFileSync(path.join(__dirname, "calendarActionsSchema.ts"), "utf8");
const translator = createJsonTranslator<CalendarActions>(model, schema, "CalendarActions");
translator.validator.stripNulls = true;

// Process requests interactively or from the input file specified on the command line
processRequests("📅> ", process.argv[2], async (request) => {
    const response = await translator.translate(request);
    if (!response.success) {
        console.log(response.message);
        return;
    }
    const calendarActions = response.data;
    console.log(JSON.stringify(calendarActions, undefined, 2));
    if (calendarActions.actions.some(item => item.actionType === "unknown")) {
        console.log("I didn't understand the following:");
        for (const action of calendarActions.actions) {
            if (action.actionType === "unknown") console.log(action.text);
        }
        return;
    }
});

@robgruen
Copy link
Copy Markdown
Contributor

robgruen commented Jun 1, 2026

I think we would want a stricter approach to providing request configuration or maybe even a hook as an alternate approach. Passing through credentials and other unknowns is something we probably want to avoid.

@robgruen robgruen closed this Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants